<template>

  <el-dialog title="CPD日期修改" :visible.sync="dialogVisible" :close-on-click-modal="false" width="35%">

    <el-form ref="main-form" :gutter="24" :model="form" :rules="rules" label-width="120px" label-position="right" >

      <el-form-item label="单号" size="mini" prop="tradeNo">
        <el-input placeholder="" v-model="tradeNo" type="textarea" readonly></el-input>
      </el-form-item>  

      <el-form-item label="CPD日期" size="mini" prop="cpdTime">
        <el-date-picker type="date" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss" v-model="form.cpdTime"></el-date-picker>
      </el-form-item>

    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="close" size="small">取 消</el-button>
      <el-button type="primary" @click="submit" size="small" :loading="loading">提 交</el-button>
    </div>

  </el-dialog>
</template>

<script>

import ApiMain from '@/api/trade.disnotify';
import SysComplaintApiMain from '@/api/platform.complaintRespMsg';
import { disIsComplaintOptions, disIsMchSeeOptions, disIsSpecialOptions, disHandleStatusOptions } from '@/const/constant';

export default {
  mixins: [
  ],
  props: [
  ],
  data () {
    return {

      dialogVisible: false,
      popDeleteVisible: false,
      loading: false,

      form: {
        ids: '',
        cpdTime: '',
      },

      rules: {
        cpdTime: [
          { required: true, message: '请输入cpd日期', trigger: 'blur' },
        ],
      },

      id: null,
      tradeNo  : null,
      data: null,

    }
  },

  watch: {
    'form.transReasonId' (newVal) {
      this.transReasonIdOptions.forEach(item => {
        if (item.value == newVal) {
          this.form.transReason = item.label
        }
      })
    }
  },

  mounted () {
  },

  methods: {

    show (rows) {

      this.reset();
      this.fetchData(rows);
      this.dialogVisible = true;
      
    },

    close () {
      this.dialogVisible = false;
      this.$emit('dialog-close');
    },

    reset () {
      this.form = {
        ids: '',
        cpdTime: '',
      };
    },

    fetchData (rows) {
      
      let tradeNo = [], ids = []
      rows.forEach(item => {
        tradeNo.push(item.tradeNo)
        ids.push(item.id)
      })
      this.form.ids = ids.join(',')
      this.tradeNo = tradeNo.join(',')
    },

    verifyForm () {
      var bool = true;
      this.$refs['main-form'].validate((valid) => bool = valid);
      return bool;
    },

    async submit () {

      if (! this.verifyForm()) return false;

      this.loading = true;

      try {
        await this.submitSet();
      } finally {
        this.loading = false;
      }
    },

    async submitSet () {

      await ApiMain.handleCpdTime(this.form);
      this.$message({message: '修改成功', type: 'success'});
      this.close();

    },

  }
}
</script>

<style>

</style>
